<!DOCTYPE html>



  


<html class="theme-next muse use-motion" lang="zh-Hans">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">



  
  
    
    
  <script src="/lib/pace/pace.min.js?v=1.0.2"></script>
  <link href="/lib/pace/pace-theme-center-minimal.min.css?v=1.0.2" rel="stylesheet">







<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.1.3" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon.png?v=5.1.3">


  <link rel="icon" type="image/png" sizes="32x32" href="http://7xqdz8.com1.z0.glb.clouddn.com/avatar.png?v=5.1.3">


  <link rel="icon" type="image/png" sizes="16x16" href="http://7xqdz8.com1.z0.glb.clouddn.com/avatar.png?v=5.1.3">


  <link rel="mask-icon" href="/images/logo.svg?v=5.1.3" color="#222">





  <meta name="keywords" content="Android,经验," />










<meta name="description" content="问题对于 Android 初学者，可能对这个问题会比较疑惑: 对于一个 View，比如 Button，如果为其设置多次点击监听 OnClickListener 回调方法，同时还在布局中设置了 onClick 属性，并且也实现了点击回调方法，那么问题来了，哪些回调方法会执行呢？又是以怎样的顺序执行呢？请跟随脚步和我一探究竟…">
<meta property="og:type" content="article">
<meta property="og:title" content="Android 中多次设置 OnClickListener 只执行一次吗？">
<meta property="og:url" content="/2017/01/06/OnClickListener/index.html">
<meta property="og:site_name" content="一路前行">
<meta property="og:description" content="问题对于 Android 初学者，可能对这个问题会比较疑惑: 对于一个 View，比如 Button，如果为其设置多次点击监听 OnClickListener 回调方法，同时还在布局中设置了 onClick 属性，并且也实现了点击回调方法，那么问题来了，哪些回调方法会执行呢？又是以怎样的顺序执行呢？请跟随脚步和我一探究竟…">
<meta property="og:updated_time" content="2017-01-07T03:39:52.005Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Android 中多次设置 OnClickListener 只执行一次吗？">
<meta name="twitter:description" content="问题对于 Android 初学者，可能对这个问题会比较疑惑: 对于一个 View，比如 Button，如果为其设置多次点击监听 OnClickListener 回调方法，同时还在布局中设置了 onClick 属性，并且也实现了点击回调方法，那么问题来了，哪些回调方法会执行呢？又是以怎样的顺序执行呢？请跟随脚步和我一探究竟…">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/',
    scheme: 'Muse',
    version: '5.1.3',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="/2017/01/06/OnClickListener/"/>





  <title>Android 中多次设置 OnClickListener 只执行一次吗？ | 一路前行</title>
  





  <script type="text/javascript">
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?8193f7e44c62cdda245d5f109196c830";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>




</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">一路前行</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">Always believe that some thing wonderful is about to happen.</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br />
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            归档
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
            
            关于
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="/2017/01/06/OnClickListener/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Voyager">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="http://7xqdz8.com1.z0.glb.clouddn.com/avatar.png">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="一路前行">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">Android 中多次设置 OnClickListener 只执行一次吗？</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2017-01-06T23:00:00+08:00">
                2017-01-06
              </time>
            

            

            
          </span>

          
            <span class="post-category" >
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Android/" itemprop="url" rel="index">
                    <span itemprop="name">Android</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h1 id="u95EE_u9898"><a href="#u95EE_u9898" class="headerlink" title="问题"></a>问题</h1><p>对于 Android 初学者，可能对这个问题会比较疑惑: 对于一个 <code>View</code>，比如 <code>Button</code>，如果为其设置多次点击监听 <code>OnClickListener</code> 回调方法，同时还在布局中设置了 <code>onClick</code> 属性，并且也实现了点击回调方法，那么问题来了，哪些回调方法会执行呢？又是以怎样的顺序执行呢？请跟随脚步和我一探究竟…</p>
<a id="more"></a>
<h1 id="u5B9E_u9A8C_u73B0_u8C61"><a href="#u5B9E_u9A8C_u73B0_u8C61" class="headerlink" title="实验现象"></a>实验现象</h1><p>我们先来做个实验，观察一下实验现象。<br>首先在布局文件中声明一个 <code>Button</code>，并为其设置好点击属性:<br><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="title">Button</span></span><br><span class="line">    <span class="attribute">android:id</span>=<span class="value">"@+id/btn"</span></span><br><span class="line">    <span class="attribute">android:layout_width</span>=<span class="value">"wrap_content"</span></span><br><span class="line">    <span class="attribute">android:layout_height</span>=<span class="value">"wrap_content"</span></span><br><span class="line">    <span class="attribute">android:onClick</span>=<span class="value">"click()"</span></span><br><span class="line">    <span class="attribute">android:text</span>=<span class="value">"BUTTON"</span>/&gt;</span></span><br></pre></td></tr></table></figure></p>
<p>嗯，对，然后再在 <code>Activity</code> 中实现方法:<br><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">click</span><span class="params">(View v)</span> </span>&#123;</span><br><span class="line">    Log.i(TAG, <span class="string">"click: in layout file"</span>);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>这样第一组测试样例放置好了，第二组和第三组很容易，先后在 <code>onCreate()</code> 中设置两次监听，都记得打上 <code>Log</code> 日志:<br><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">mButton.setOnClickListener(<span class="keyword">new</span> View.OnClickListener() &#123;</span><br><span class="line">    <span class="annotation">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">onClick</span><span class="params">(View v)</span> </span>&#123;</span><br><span class="line">        Log.i(TAG, <span class="string">"click: in onCreate() first"</span>);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;);</span><br><span class="line">mButton.setOnClickListener(<span class="keyword">new</span> View.OnClickListener() &#123;</span><br><span class="line">    <span class="annotation">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">onClick</span><span class="params">(View v)</span> </span>&#123;</span><br><span class="line">        Log.i(TAG, <span class="string">"click: in onCreate() second"</span>);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure></p>
<p>然后，见证奇迹了，运行观察实验结果:<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">I/MainActivity: click: in onCreate() second</span><br></pre></td></tr></table></figure></p>
<p>你没有看错，只有一条结果，而且是第二次的结果，说明优先级 <code>java</code> 设置监听的优先级大于布局文件，而且最后一次设置的监听会覆盖前一次设置的监听。</p>
<blockquote>
<p><strong>结论</strong><br>点击监听优先级: 之后设置的优先级大于之前设置的优先级，代码中设置的优先级大于布局中设置的优先级</p>
</blockquote>
<h1 id="u5BFB_u627E_u7B54_u6848"><a href="#u5BFB_u627E_u7B54_u6848" class="headerlink" title="寻找答案"></a>寻找答案</h1><p>结果很出乎意料，也许猜的都会执行，也许你猜的布局先执行，却没想到只有最后一次设置的执行，这其中的神秘之处究竟何在呢？让我们 Read The Fuck Source Code.</p>
<h2 id="setOnClickListener"><a href="#setOnClickListener" class="headerlink" title="setOnClickListener"></a>setOnClickListener</h2><p>先从 <code>setOnClickListener()</code> 入手:<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">public void setOnClickListener(@Nullable OnClickListener l) &#123;&#10;    if (!isClickable()) &#123;&#10;        setClickable(true);&#10;    &#125;&#10;    getListenerInfo().mOnClickListener = l;&#10;&#125;</span><br></pre></td></tr></table></figure></p>
<p>先是将该 <code>View</code> 设置为可点击状态，所以即便一个 <code>View</code> 是不可点击的，你为其设置了监听，也会将其恢复成可点击状态。再是将 <code>getListenerInfo()</code> 返回的对象中的成员 <code>mOnClickListener</code> 直接复制为参数 <code>l</code>，还不明白？再看:<br><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line"><span class="function">ListenerInfo <span class="title">getListenerInfo</span><span class="params">()</span> </span>&#123;</span><br><span class="line">    <span class="keyword">if</span> (mListenerInfo != <span class="keyword">null</span>) &#123;</span><br><span class="line">        <span class="keyword">return</span> mListenerInfo;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="comment">// 如果为空，重新创建用于保存所有监听器的容器类</span></span><br><span class="line">    mListenerInfo = <span class="keyword">new</span> ListenerInfo();</span><br><span class="line">    <span class="keyword">return</span> mListenerInfo;</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">// 容器类定义</span></span><br><span class="line"><span class="keyword">static</span> <span class="class"><span class="keyword">class</span> <span class="title">ListenerInfo</span> </span>&#123;</span><br><span class="line">    ...</span><br><span class="line">    <span class="comment">// 是数组 事件发生回调所有监听器</span></span><br><span class="line">    <span class="keyword">private</span> CopyOnWriteArrayList&lt;OnAttachStateChangeListener&gt; mOnAttachStateChangeListeners;</span><br><span class="line">    </span><br><span class="line">    <span class="comment">// 不是数组 直接对其进行赋值</span></span><br><span class="line">    <span class="keyword">public</span> OnClickListener mOnClickListener;</span><br><span class="line">    </span><br><span class="line">    <span class="keyword">protected</span> OnLongClickListener mOnLongClickListener;</span><br><span class="line">    ...</span><br></pre></td></tr></table></figure></p>
<p>哈，是不是恍然大悟，所以每一次设置监听都是对这个 <code>mOnClickListener</code> 成员进行替换赋值，所以说最后一次设置监听才是有效的。</p>
<h2 id="u5E03_u5C40_u6587_u4EF6"><a href="#u5E03_u5C40_u6587_u4EF6" class="headerlink" title="布局文件"></a>布局文件</h2><p> <code>Java</code> 中的监听确实明白了，那么布局文件中又是怎么回事呢？<br> 通过 <code>setOnClickListener()</code> 可以对 <code>mOnClickListener</code> 进行修改，那么我们找一下这个函数在哪里有调用，果然找到了，<br>在 <code>View</code> 的构造函数中，有这样两行代码:<br><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// 获取布局 android:onClick="" 属性值</span></span><br><span class="line"><span class="keyword">final</span> String handlerName = a.getString(attr);</span><br><span class="line"><span class="keyword">if</span> (handlerName != <span class="keyword">null</span>) &#123;</span><br><span class="line">    setOnClickListener(<span class="keyword">new</span> DeclaredOnClickListener(<span class="keyword">this</span>, handlerName));</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>也就是说，<code>View</code> 默认就设置了一个叫做 <code>DeclaredOnClickListener</code> 的监听器:<br><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">private</span> <span class="keyword">static</span> <span class="class"><span class="keyword">class</span> <span class="title">DeclaredOnClickListener</span> <span class="keyword">implements</span> <span class="title">OnClickListener</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    ...</span><br><span class="line">    <span class="annotation">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">onClick</span><span class="params">(@NonNull View v)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">if</span> (mMethod == <span class="keyword">null</span>) &#123;</span><br><span class="line">            mMethod = resolveMethod(mHostView.getContext(), mMethodName);</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="comment">// 调用方法，并携带参数 v</span></span><br><span class="line">        mMethod.invoke(mHostView.getContext(), v);</span><br><span class="line">        ...</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure></p>
<p>默认的实现是通过 <code>resolveMethod()</code> 获取到方法，并调用之:<br><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">private</span> Method <span class="title">resolveMethod</span><span class="params">(@Nullable Context context, @NonNull String name)</span> </span>&#123;</span><br><span class="line">    ...</span><br><span class="line">    <span class="keyword">if</span> (!context.isRestricted()) &#123;</span><br><span class="line">        <span class="comment">// 使用参数 name 反射取得方法</span></span><br><span class="line">        <span class="keyword">return</span> context.getClass().getMethod(mMethodName, View.class);</span><br><span class="line">    &#125;</span><br><span class="line">    ...</span><br></pre></td></tr></table></figure></p>
<p>是不是很眼熟了，这不就是反射获取到方法吗？！一切都明白了吧，在 <code>View</code> 创建之初就设置了一个默认监听， 默认监听是调用的所在 <code>Context</code> 中的符合布局中定义的方法签名的方法。</p>
<h1 id="u7ED3_u8BBA"><a href="#u7ED3_u8BBA" class="headerlink" title="结论"></a>结论</h1><p>所以，总的来说是这样的，<code>View</code> 在构造之初就默认设置好了一个监听器，<code>View</code> 的构造也是在 <code>onCreate()</code> 方法执行前完成的，对于每一次设置监听都会覆盖上一次的监听，所以最后一次设置的监听才会是有效的。</p>

      
    </div>
    
    
    

    

    
      <div>
        <div style="padding: 10px 0; margin: 20px auto; width: 90%; text-align: center;">
  <div></div>
  <button id="rewardButton" disable="enable" onclick="var qr = document.getElementById('QR'); if (qr.style.display === 'none') {qr.style.display='block';} else {qr.style.display='none'}">
    <span>打赏</span>
  </button>
  <div id="QR" style="display: none;">

    
      <div id="wechat" style="display: inline-block">
        <img id="wechat_qr" src="http://7xqdz8.com1.z0.glb.clouddn.com/pay_weixin.png" alt="Voyager 微信支付"/>
        <p>微信支付</p>
      </div>
    

    
      <div id="alipay" style="display: inline-block">
        <img id="alipay_qr" src="http://7xqdz8.com1.z0.glb.clouddn.com/pay_alipay.jpg" alt="Voyager 支付宝"/>
        <p>支付宝</p>
      </div>
    

    

  </div>
</div>

      </div>
    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/Android/" rel="tag"># Android</a>
          
            <a href="/tags/经验/" rel="tag"># 经验</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/2016/12/26/Linux_process/" rel="next" title="初探 Linux 系统编程之进程">
                <i class="fa fa-chevron-left"></i> 初探 Linux 系统编程之进程
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/2017/01/18/LruCache/" rel="prev" title="Android LruCache 源码分析">
                Android LruCache 源码分析 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          
  


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image"
                src="http://7xqdz8.com1.z0.glb.clouddn.com/avatar.png"
                alt="Voyager" />
            
              <p class="site-author-name" itemprop="name">Voyager</p>
              <p class="site-description motion-element" itemprop="description">Android Developer</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/archives/">
              
                  <span class="site-state-item-count">41</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/categories/index.html">
                  <span class="site-state-item-count">8</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                
                  <span class="site-state-item-count">10</span>
                  <span class="site-state-item-name">标签</span>
                
              </div>
            

          </nav>

          

          <div class="links-of-author motion-element">
            
              
                <span class="links-of-author-item">
                  <a href="https://github.com/a-voyager" target="_blank" title="GitHub">
                    
                      <i class="fa fa-fw fa-github"></i>GitHub</a>
                </span>
              
                <span class="links-of-author-item">
                  <a href="mailto:w19961009@126.com" target="_blank" title="E-Mail">
                    
                      <i class="fa fa-fw fa-envelope"></i>E-Mail</a>
                </span>
              
                <span class="links-of-author-item">
                  <a href="https://weibo.com/u/2306071720" target="_blank" title="微博">
                    
                      <i class="fa fa-fw fa-weibo"></i>微博</a>
                </span>
              
            
          </div>

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#u95EE_u9898"><span class="nav-number">1.</span> <span class="nav-text">问题</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#u5B9E_u9A8C_u73B0_u8C61"><span class="nav-number">2.</span> <span class="nav-text">实验现象</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#u5BFB_u627E_u7B54_u6848"><span class="nav-number">3.</span> <span class="nav-text">寻找答案</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#setOnClickListener"><span class="nav-number">3.1.</span> <span class="nav-text">setOnClickListener</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#u5E03_u5C40_u6587_u4EF6"><span class="nav-number">3.2.</span> <span class="nav-text">布局文件</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#u7ED3_u8BBA"><span class="nav-number">4.</span> <span class="nav-text">结论</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; 2015 &mdash; <span itemprop="copyrightYear">2017</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">WuHaojie</span>

  
</div>









        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  


  











  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>

  
  <script type="text/javascript" src="/lib/canvas-nest/canvas-nest.min.js"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.1.3"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.1.3"></script>



  
  

  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.3"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.1.3"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.3"></script>



  


  




	





  





  








  





  

  

  

  

  

  

</body>
</html>
